//
//  DYMineVC.m
//  kafuMerchant
//
//  Created by 帝云科技 on 2018/9/10.
//  Copyright © 2018年 帝云科技. All rights reserved.
//

#import "DYMineVC.h"
#import "DYNavigationController.h"
#import "DYMineHeaderView.h"
#import "DYMineCell.h"
#import "DYShopDecorateVC.h"
#import "DYShopInfoVC.h"
#import "DYSetCollectionVC.h"
#import "DYIssueCardsVC.h"
#import "DYShopAuthVC.h"
#import "DYAboutUsVC.h"
#import "DYSetVC.h"
#import "DYLoginVC.h"
#import "DYRegisterVC.h"
#import "DYShareVC.h"

@interface DYMineVC ()

@property (nonatomic,strong)DYMineHeaderView *headerView;
@property (nonatomic,strong)UIButton *setButton;

@end

@implementation DYMineVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.fd_prefersNavigationBarHidden=YES;
}
-(void)dy_initUI
{
    [super dy_initUI];
    
    [self.view addSubview:self.setButton];
    
    self.tableView.frame=CGRectMake(0, 0, kScreenWidth, kScreenHeight-kTabBarHeight);
    
    self.tableView.tableHeaderView=self.headerView;
    
    [self.tableView registerClass:[DYMineCell class] forCellReuseIdentifier:@"DYMineCell"];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return BILIHEIGHT(45);
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DYMineCell *cell=[tableView dequeueReusableCellWithIdentifier:@"DYMineCell" forIndexPath:indexPath];
    
    NSArray *imageArray=@[@"icon_infor_mine",@"icon_invit_mine",@"icon_tel_mine",@"icon_about_mine"];
    NSArray *titleArray=@[@"商铺信息",@"推荐给朋友",@"客服热线",@"关于我们"];
    
    cell.imageView.image=[UIImage imageNamed:imageArray[indexPath.row]];
    cell.textLabel.text=titleArray[indexPath.row];

    if (indexPath.row==2) {
        cell.contentLabel.text=@"010-8888888";
    }

    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
    if (indexPath.row==0) {
        DYShopInfoVC *vc=[[DYShopInfoVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row==1){
        DYShareVC *vc=[[DYShareVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (indexPath.row==2){
        NSString *phone=@"010-888888";
        if (@available(iOS 10.0, *)) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phone]] options:@{} completionHandler:nil];
        } else {
            // Fallback on earlier versions
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phone]]];
        }
    }else{
        DYAboutUsVC *vc=[[DYAboutUsVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
#pragma mark -  设置
-(void)setButtonClick
{
    DYSetVC *vc=[[DYSetVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
-(DYMineHeaderView *)headerView
{
    if (!_headerView) {
        CGFloat height;
        if (XHQ_iPhoneX) {
            height=BILIHEIGHT(224+90);
        }else{
            height=BILIHEIGHT(200+90);
        }
        _headerView=[[DYMineHeaderView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, height)];
   
        @weakify(self);
        _headerView.mineBlock = ^(NSString *text) {
            @strongify(self);
            if ([text isEqualToString:@"我要装修"]) {
                DYShopDecorateVC *vc=[[DYShopDecorateVC alloc]init];
                [self.navigationController pushViewController:vc animated:YES];
            }else if ([text isEqualToString:@"我要收款"]){
                DYSetCollectionVC *vc=[[DYSetCollectionVC alloc]init];
                [self.navigationController pushViewController:vc animated:YES];
            }else if ([text isEqualToString:@"我要发卡"]){
                DYIssueCardsVC *vc=[[DYIssueCardsVC alloc]init];
                [self.navigationController pushViewController:vc animated:YES];
            }else if ([text isEqualToString:@"我要认证"]){
                DYShopAuthVC *vc=[[DYShopAuthVC alloc]init];
                [self.navigationController pushViewController:vc animated:YES];
            }else if ([text isEqualToString:@"注册"]){
                DYRegisterVC *vc=[[DYRegisterVC alloc]init];
                 DYNavigationController *nav=[[DYNavigationController alloc]initWithRootViewController:vc];
                [self presentViewController:nav animated:YES completion:nil];
            }else{
                DYLoginVC *vc=[[DYLoginVC alloc]init];
                DYNavigationController *nav=[[DYNavigationController alloc]initWithRootViewController:vc];
                [self presentViewController:nav animated:YES completion:nil];
            }
        };
    }
    return _headerView;
}
-(UIButton *)setButton
{
    if (!_setButton) {
        _setButton=[Utils createBtnWithType:UIButtonTypeCustom backgroundColor:ClearColor action:@selector(setButtonClick) target:self title:nil image:@"icon_set_mine" font:12 textColor:WhiteColor];
        _setButton.frame=CGRectMake(kScreenWidth-50, kNavigationStatusHeight-40, 50, 40);
    }
    return _setButton;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
